{extend name="common/base"/}
<!-- 主体 -->
{block name="body"}
<div class="layui-form p-4">
<h3 class="pb-3">导入</h3>
<!-- <form action="/admin/order/upload" method="post" enctype="multipart/form-data">
    <input type="file" name="excel_file">
    <button type="submit">导入</button>
</form> -->
<div class="layui-btn-container">
	<table class="layui-table layui-table-form">
		<tr><td class="layui-td-gray-2">县区</td>
			<td>
				
				<select name="region" id="region" lay-reqText="请选择县区" lay-search=""  lay-filter="region">
					<option value="0">--请选择县区--</option>
					{volist name=":get_region()" id="v"}
					<option value="{$v.id}">{$v.nianji} </option>
					{/volist}
				</select>
			</td>
			<input type="hidden" id="region_id">
		</tr>
	</table>
  <button type="button" class="layui-btn layui-btn-normal" id="ID-upload-demo-choose">选择文件</button>
</div>
<div style="font-size: 18px;"><font style="color:red">*</font>请注意，请先下载导入模板并按照模板样式填充内容后进行导入</div>
<div style="margin-top:10px;font-size: 18px;">下载导入模板：</br>
	<a href="/download/hedong.xlsx" style="color:red">河东模板</a></br>
	<a href="/download/导入模板样式.xls" style="color:red">其他县区模板</a>
</div>
</div>
{/block}
<!-- /主体 -->

<!-- 脚本 -->
{block name="script"}
<script>
	const moduleInit = ['tool'];
	function gouguInit() {
		var tool = layui.tool, form = layui.form,upload = layui.upload;
		  // 渲染
		var region=$("#region").val();
		console.log(region);
		form.on('select(region)', function (data) {
		　　let val = data.value;
				console.log(val);
				$("#region_id").val(val);
			/*console.log(shichang);
			
			console.log(data);*/
		});
		var uploadInst = upload.render({
  elem: '#ID-upload-demo-choose',
  url: '/admin/order/upload',
  accept: 'file',
  exts: 'jpeg|jpg|png|gif|doc|docx|ppt|pptx|xls|xlsx|pdf|zip|rar|7z',
  data: {
    region: function() { 
      return $("#region_id").val();
    }
  },
  choose: function(obj) { 
    showLoad(); // 启动动画
    
    
  },
  done: function(e) {
    closeLoad(showLoad()); // 关闭动画
    if (e.code == 0) {
      layer.msg(e.msg + ":导入数据:" + e.data.count + "行", {icon: 1, time: 3000}, function() {
        var index = parent.layer.getFrameIndex(window.name);

        //parent.layer.close(index);
        setTimeout(function () {
						parent.location.reload();
					}, 500);	
      });
    } else {
      layer.msg(e.msg, {icon: 2});
    }
  },
  error: function(e) { // ✅ 统一错误处理
    closeLoad(showLoad());
    layer.msg('上传失败: ' + (e.message || e.status), {icon: 2});
  }
});
	  /*var uploadInst = upload.render({
	    elem: '#ID-upload-demo-choose',
	    url: '/admin/order/upload', // 此处配置你自己的上传接口即可
	    accept: 'file',
	    exts: 'jpeg|jpg|png|gif|doc|docx|ppt|pptx|xls|xlsx|pdf|zip|rar|7z',
	    data: {
		    region: function() { // 每次上传时实时获取最新值
		      return $("#region_id").val();
		    }
		  },
	    choose: function (obj) 
	    {      
	    	
	    showLoad();//启动动画
	    
                
         },
	    done: function(e){
	    	closeLoad(showLoad());//成功后关闭动画
	    	if(e.code == 0){
	    		layer.msg(e.msg+":导入数据:"+e.data.count+"行",{icon: 1,time:3000},function(){
	    			var index = parent.layer.getFrameIndex(window.name); // 先得到当前 iframe 层的索引
    				parent.layer.close(index); // 再执行关闭

	    		});
	    		    
	    	}else{
	    		layer.msg(e.msg,{icon: 2},);
	    	}
	      
	    }
	  });*/

		
	}
	//执行动画
	function showLoad() {
        return layer.msg('执行中...', { icon: 6, shade: [0.5, '#f5f5f5'], scrollbar: false, offset: 'auto', time: 100000000 });
    }
    //关闭动画
    function closeLoad(index) {
        layer.close(index);
    }
</script>
{/block}
<!-- /脚本 -->